import * as apiService from '@/services/api';

/**
 * 模糊搜索代理列表
 * @param {string} username 代理账号
 * @returns {*} Promise
 *
 */
const searchAgencyList = params => apiService.post('/gl/user/manage/search/proxy', params);
/**
 * 添加/编辑代理信息
 * @param {number} uid 代理ID require
 * @param {number} ruleId 手续费方案ID require
 * @param {string} username 用户名 require
 * @param {string} password 密码 require
 * @param {string} rebate 返佣模式 require
 * @param {string} proxy 上级代理
 * @returns {*} Promise
 *
 */
export function updateAgencyCommission({
  username,
  password,
  rebate, // 返佣模式
  proxy,

  uid,
  ruleId, // 返佣模式ID
} = {}) {
  if (uid) {
    return apiService.post('/gl/proxy/rule/set/fee', {
      uid,
      ruleId,
    });
  }
  return apiService.post('/gl/proxy/manage/add', {
    username,
    password,
    rebate,
    proxy,
  });
}
/**
 * 获取代理审核列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyAuditList = params => apiService.post(api.AGENCY_AUDIT_LIST, params);
/**
 * 获取代理审核人列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyAuditorList = params =>
  // console.log(params)
  apiService.post(api.AGENCY_AUDITOR_LIST, params);

/**
 * 更新代理审核状态
 * @param params
 * @returns {Promise<*>}
 *
 */
const updateAgencyAudit = (params) => {
  // /gl/proxy/manage/approve/first
  const {
    proxyId, status, remark, step,
  } = params;
  if (step === 1) {
    return apiService.post(api.AGENCY_AUDIT_UPDATE, { proxyId, status, remark });
  }
  if (step === 2) {
    return apiService.post(api.AGENCY_AUDIT_UPDATE_SECOND, { proxyId, status, remark });
  }
};

/**
 * 获取佣金链配置
 * @param {number} uid 代理ID require
 * @returns {*} Promise
 *
 */
export function getAgencyProxyLine({
  uid,
} = {}) {
  return apiService.post('/gl/proxy/rule/get/line', {
    uid,
  });
}

/**
 * 更新佣金链配置
 * @param {number} uid 代理ID require
 * @param {number} cashRuleId 会员佣金方案
 * @param {number} commMode 佣金链模式 require
 * @param {number} minEffectMemberNum 最小有效会员数
 * @param {array} commLine 佣金链列表 require
 * {
 *   uid/name/level/rate
 * }
 * @returns {*} Promise
 *
 */
export function updateAgencyProxyLine({
  uid,
  cashRuleId,
  commMode,
  minEffectMemberNum,
  commLine,
  rateTotal,
} = {}) {
  return apiService.post('/gl/proxy/rule/set/line', {
    uid,
    cashRuleId,
    commMode,
    minEffectMemberNum,
    commLine,
    rateTotal,
  });
}

/**
 * 获取代理树当前节点
 * @param {string} userName 代理账号
 * @returns {*} Promise
 *
 */
export function getProxyTreeSearch({
  userName,
} = {}) {
  return apiService.post('/gl/proxy/tree/search', {
    userName,
  });
}

/**
 * 获取代理树子节点
 * @param {number} uid 代理ID
 * @returns {*} Promise
 *
 */
export function getProxyTreeChild({
  uid,
} = {}) {
  return apiService.post('/gl/proxy/tree/child', {
    uid,
  });
}

/**
 * 获取代理树详情
 * @param {number} uid 代理ID
 * @returns {*} Promise
 *
 */
export function getProxyTreeDetails({
  uid,
} = {}) {
  return apiService.post('/gl/proxy/tree/detail', {
    uid,
  });
}

/**
 * 获取代理域名列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyDomainList = params => apiService.post(api.AGENCY_DOMAIN_LIST, params);
/**
 * 获取代理域名详情
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyDomainDetail = params => apiService.post(api.AGENCY_DOMAIN_DETAIL, params);
/**
 * 编辑代理域名
 * @param params
 * @returns {Promise<*>}
 *
 */
const editAgencyDomain = params => apiService.post(api.AGENCY_DOMAIN_EDIT, params);
/**
 * 查询代理用户域名
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyDomainListDetail = (params) => {
  Object.assign(params, { page: 1, size: 23 });
  return apiService.post(api.AGENCY_DOMAIN_LIST_DETAIL, params);
};

/**
 * 查询代理上分设置
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyCredit = params => apiService.post(api.AGENCY_CREDIT_CONFIG, params);
/**
 * 代理近三个月的佣金平均值
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyCreditInfo = params => apiService.post(api.AGENCY_CREDIT_CREDIT, params);
/**
 * 查询代理上分的使用金额
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAgencyCreditAmount = params => apiService.post(api.AGENCY_CREDIT_AMOUNT, params);
/**
 * 修改代理上分设置
 *
 * @param params
 * @returns {Promise<*>}
 *
 */
const updateAgencyCredit = params => apiService.post(api.AGENCY_CREDIT_CONFIG_UPDATE, params);

/**
 * 手机邮箱记录
 * @param params
 * @returns {Promise<*|*|*|undefined>}
 */
const agencyContactModify = params => apiService.post(api.MEMBER_AGENCY_CONTACT_MODIFY, params);

export {
  getAgencyAuditList,
  getAgencyDomainList,
  updateAgencyAudit,
  getAgencyDomainDetail,
  editAgencyDomain,
  getAgencyDomainListDetail,
  getAgencyCredit,
  getAgencyCreditInfo,
  getAgencyCreditAmount,
  updateAgencyCredit,
  getAgencyAuditorList,
  searchAgencyList,
  agencyContactModify,
};
